<%@page import="com.jm.web.form.Toolbar"%>
<%@page import="com.jm.web.form.Button"%>
<%@page import="com.jm.web.form.Separate"%>
<%@ page language="java" contentType= "text/html" pageEncoding="UTF-8"%>
<%@include file="/include/common/wfpageuihead1.jsp"%>
<%
	page1.getPageTitle().setEnab(false);
%>
<%@include file="/include/common/wfpageuihead2.jsp"%>
<%
	page1.getPageTitle().setTitle("電腦賬號管理right");
	Separate sep = new Separate();
	List btns1 = new ArrayList();
	if(!form.isCanEditWFState() && !page1.isWFCheckPage()){
		Button bt1 = Toolbar.getNewButton("人員儲存","custbtn","custbtn","xt-btn-icon sx-tb-saverow",null);
		bt1.setOnClick("saverow(this,event);");
		btns1.add(bt1);
		btns1.add(sep);
		Button bt2 = Toolbar.getNewButton("人員送簽","custbtn","custbtn","xt-btn-icon sx-tb-start",null);
		bt2.setOnClick("startrow(this,event);");
		btns1.add(bt2);
	}else if(page1.isWFCheckPage() && form.getJMStatus().equals("1")){
		Button bt2 = Toolbar.getNewButton("確認","custbtn","custbtn","xt-btn-icon sx-tb-ok",null);
		bt2.setOnClick("confirmrow(this,event);");
		btns1.add(bt2);
	}
%>
<jm:form>
<jm:layout postion="north">
	<jm:toolbar newEnab="false" printDisabled="true" exportDisabled="true" searchDisabled="true" saveDisabled="false" deleteDisabled="false">
		<button name="newnext" icon="sx-tb-new" pos="1" value="新增下一筆" onclick="newNextRecord();"/>
	</jm:toolbar>
	<jm:pageTitle />
	<jm:sp id="sp1" data="<%=Utils.TAG_FORM%>" tabSize="1" customtab="" tabSize="<%=page1.hasWFInstance() ? 1 : 2%>" customtab="<%=page1.hasWFInstance() ? "申請電腦基本信息|簽核記錄" : "申請電腦基本信息"%>" cache="false">
	    <jm:tab colModel="250px;*">
	    	<jm:group captionDisplay="false" colspan="2" hidden="true">
	    		<input type="text" name="applysn" caption="applysn"/>
	    		<input type="text" name="applychname" caption="applychname"/>
	    	</jm:group>
	    	
	        <jm:combobox name="hr003atsn" caption="申請公司別" trigger="all"  dataSource="info5" sql="select tsn,companyNameCh from hr..hr003a where enab > 0" width="150px" required="true"/>
	        <jm:org name="hr003" caption="部門" width="150px" required="true"  />
	       
	       <input name="IP" caption="IP" type="text" width="150px" required="true" />
	        <jm:field caption="申請人" required="true" name="applyhrnum" >
				<input type="text" name="applyhrnum" caption="申請人" 
					onchange="if(this.value.trim() != '')$P.cmp({me:this,cmpid:'cmp001',hrnum:this.value,async:false});" 
					ajaxsucc="$('input[name=applychname]').val(jo.data['chname']);$('span[id=applychname]').text(jo.data['chname']);"
					ajaxfail="$('input[name=applychname]').val('');$('span[id=applychname]').text('');me.value='';" width="150px" />
				&nbsp;<span id="applychname" bind="true"></span>
			</jm:field>
			
			<jm:field caption="單據狀態" colspan="2">
				<span style="color: blue;">&nbsp;<%=form.transJMStatus()%></span>
			</jm:field>
	    </jm:tab>
	     <%if(page1.hasWFInstance()){%>
			<jm:tab src="<%="/jmPro/subPro/public/wf001Q.jsp?wfinstance="+form.getWFInstance()%>" delay="true" />
		<%}%>
	</jm:sp>
	<jm:error/>
</jm:layout>

<jm:layout postion="center">
	<jm:columnEditors>
		<jm:columnEditor id="e_hrnum" type="text">
			<input name="e_hrnum" type="text" autocomplete="off" />
		</jm:columnEditor>
	</jm:columnEditors>
	<br>
	<jm:table id="grid1" dataSet="<%=ret.getSerchResult()%>" toolbar="true" loopFisrt="true"  addRowConfig="reset:grid_reset"
		toolbarConfig="<%=!page1.isWFCheckPage() ? "addrowEnab:true,deleterowEnab:true" : "addrowEnab:false,deleterowEnab:false"%>"
		deleteRowConfig="tr:grid1_deleterow" 
		toolbarButtons="<%=btns1%>"
		>
		<jm:thead>
			<tr><td colspan="5" style="font-size: 12px;font-weight: bold;">可以在此臺電腦登陸的人員</td></tr>
			<tr>
				<td width="30px">選</td>
				<td width="100px" config="cid:'hrnum',editor:'text',editorid:'e_hrnum',bedit:'bedit_hrnum',eedit:'eedit_hrnum'">工號</td>
				<td width="100px">姓名</td>
				<td width="*">狀態</td>
			</tr>
		</jm:thead>
		<jm:tbody>
			<jm:tr>
				<jm:td cid="col1">
					<input type="checkbox" name="key" value="<%=ret.grsv("sn")%>" />
				 	<input type="hidden" name="sn" value="<%=ret.grsv("sn")%>" />
				 </jm:td>
				<jm:td cid="hrnum" extAtr="<%=" status='"+ret.griv("status")+"'" %>"></jm:td>
				<jm:td cid="chname"></jm:td>
				<jm:td cid="status"><%="0".equals(ret.grsv("status")) ? "未送簽" : ("1".equals(ret.grsv("status")) ? "未確認" : ("2".equals(ret.grsv("status")) ? "已確認" : ""))%>&nbsp;</jm:td>
			</jm:tr>
		</jm:tbody>
	</jm:table>
</jm:layout>
</jm:form>
<jm:script><script type="text/javascript" charset="UTF-8">
	function newNextRecord(){
		if(confirm('確定新增一下筆?'))
			window.location.href='admin003_right.jsp';
	}
	
	function onsave(actionvalue,p){
		var records = $('table[id=grid1] tbody tr[dirty=true]').getRecords();
		$P.form.appendRecords(records);
		if(actionvalue == "saverow" && records.length == 0){
			alert("無人員異動!");
			return false;
		}else{
			submitForm(p);
		}
	}
	
	//以下定义其它function ,命名要取有意义的名称
	function grid_reset(tr){
		tr.find('input[name=sn],input[name=key]').val('');
		tr.find('td[cid!=col1]').html('&nbsp;');
		tr.find('td[cid=hrnum]').attr('status',"0");
	}
	
	function bedit_hrnum(config){
		return $(this).gv("status") == "0";
	}
	
	function eedit_hrnum(config){
		if(config['value'] == config['oldvalue'])return ;
		
		var tr = $(this).parent();
		var ehrnum = tr.find('td[cid=hrnum]');
		var echname = tr.find('td[cid=chname]');
		
		var p ={};
		p['action'] = "getHrnum";
		p['hrnum'] = config['value'];
		ehrnum.text('loading...');
		echname.text('');
		
		var doaction = function(jo){
			$(config['editor']).val($(jo.data).gv('hrnum'));
		   	ehrnum.text($(jo.data).gv('hrnum'));
			echname.text($(jo.data).gv('chname'));
		};
		$P.ajax({data : p,succ :doaction});
		tr = null;
		return true;
	}
	
	function saverow(){
		doAction({action:"save",actionvalue:"saverow"});
	}
	
	function startrow(){
		if($("input[name=key]:checked").length == 0){
			alert("請選擇未送簽人員!");
			return false;
		}
		doAction({action:"save",actionvalue:"startrow"});
	}
	
	function grid1_deleterow(tr){
		var keys = $('input[name=key]:checked');
		var len = keys.length;
		if(len == 0) return ;
		var len2 = 0
		keys.each(function(){
			if(this.value == ""){
				$(this).parent().parent().remove();
				len2++;
			}else{
				len2 = 0;
				return;
			}
		});
		
		if(len != len2){
			if(confirm('確定刪除選中人員?')){
				doAction({action:'delete',actionvalue:'deleteRow'});
			}
		}
		delete len;
		delete len2;
		delete keys;
		return null;
	}
</script></jm:script>
<%@include file="/include/common/wfpageuiend.jsp"%>
